---
title: "Supporting Materials"
output: pdf_document
---

```{r setup, include=FALSE}

knitr::opts_chunk$set(echo = FALSE, warning=FALSE)

setwd("C:/Users/Jphil/Documents/currentProjects/Paul Bloom/Deontic Restriction/Materials_for_publication/supportingMaterials")

library(knitr)
library(rmarkdown)
library(ggplot2)
library(plyr)
library(dplyr)
library(tidyr)

```

#Study 1a-b

Here, we include descriptive statistics about the events used in Study 1a and 1b. 


### Table 1a: Average possibility judgments for each event


```{r table1a, echo=FALSE}

t1 <- read.csv("table1.csv")

t1a <- cbind(t1[1:32,2:4],t1[33:64,4],t1[65:96,4])
colnames(t1a) <- c("Violation Type","Scenario","4-5-year-olds","6-7-year-olds","Adults")

kable(t1a,caption = "Possibility Judgments")

```

\pagebreak

### Table 1b: Average physical impossibility, immorailty, and improbability rating for each event

```{r table1b, echo=FALSE}

t1b <- t1[1:32,c(2:3,6:9)]
colnames(t1b) <- c("Violation Type","Scenario","Immorality","Improbability","Physical Imossibility","Violation Index")
t1b$`Violation Index` <- scale(t1b$`Violation Index`)

kable(t1b,caption = "Event Ratings")

```

\pagebreak

### Figure S1: Mean ratings of events in each of the four a priori categories

```{r figure 1}

t1l <- gather(t1b,judgment,rating,3:6)

t1b.sum <- ddply(t1l, c(1,3), summarise,
                 N    = length(rating),
                 mean = mean(rating, na.rm=TRUE),
                 sd   = sd(rating,na.rm=TRUE),
                 se   = sd / sqrt(N) )

t1b.sum$judgment <- factor(t1b.sum$judgment)
t1b.sum$judgment <- factor(c("Immorality","Physical Impossibility","Improbability","Violation Index")[t1b.sum$judgment])
t1b.sum$judgment <- factor(t1b.sum$judgment, levels = c("Physical Impossibility","Improbability","Immorality","Violation Index"))
t1b.sum$`Violation Type` <- factor(c("Moral","Non-violation","Physical","Statistical")[t1b.sum$`Violation Type`])
t1b.sum$`Violation Type` <- factor(t1b.sum$`Violation Type`, levels=c("Physical","Statistical","Moral","Non-violation"))

fig1 <- ggplot(t1b.sum,aes(x=judgment, y=mean, fill=judgment))+
  ylab("Mean Rating across Scenarios") +
  xlab("") +
  ggtitle("Ratings of Each Violation Type") +
  facet_grid(~`Violation Type`) +
  #coord_cartesian(ylim=c(0,100)) +
  geom_bar(position="dodge",stat="identity") +
  geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.1, position=position_dodge(.9)) +
  guides(fill = guide_legend(title = "Judgment Type")) +
  theme_bw() +
  theme(
    plot.background = element_blank()
    ,panel.grid.major = element_blank()
    ,panel.grid.minor = element_blank()
    ,legend.text=element_text(size=rel(1.33))
    #,legend.position=c(.88,.88)
    ,legend.title=element_text(size=rel(1.45))
    ,strip.text = element_text(size=rel(1.5))
    ,axis.text.y=element_text(size=rel(1.5))
    ,axis.text.x=element_blank()
    ,axis.title.y=element_text(vjust=.9)
    ,axis.ticks = element_blank()
    ,axis.title=element_text(size=rel(1.65))
    ,plot.title = element_text(hjust = 0.5,size=rel(1.5))
  ) 

```


```{r fig.width=12, fig.height=8,echo=FALSE}

print(fig1)
```

\pagebreak

# Study 2a-b

Here, we include descriptive statistics about the events used in Study 2a and 2 b. 


### Table 2a: Average magic judgments for each event


```{r table2a, echo=FALSE}

t2 <- read.csv("table2.csv")

t2a <- cbind(t2[1:32,2:4],t2[33:64,4],t2[65:96,4],t2[97:128,4])
colnames(t2a) <- c("Violation Type","Scenario","3-year-olds","4-5-year-olds","6-7-year-olds","Adults")

kable(t2a,caption = "Magic Judgments")

```

\pagebreak

### Table 2b: Average physical impossibility, immorailty, and improbability rating for each event

```{r table2b, echo=FALSE}

t2b <- t2[1:32,c(2:3,6:9)]
colnames(t2b) <- c("Violation Type","Scenario","Immorality","Improbability","Physical Imossibility","Violation Index")
t2b$`Violation Index` <- scale(t2b$`Violation Index`)

kable(t2b,caption = "Event Ratings")

```

\pagebreak

### Figure S2: Mean ratings of events in each of the four a priori categories

```{r figure 2}

t2l <- gather(t2b,judgment,rating,3:6)

t2b.sum <- ddply(t2l, c(1,3), summarise,
                 N    = length(rating),
                 mean = mean(rating, na.rm=TRUE),
                 sd   = sd(rating,na.rm=TRUE),
                 se   = sd / sqrt(N) )

t2b.sum$judgment <- factor(t2b.sum$judgment)
t2b.sum$judgment <- factor(c("Immorality","Physical Impossibility","Improbability","Violation Index")[t2b.sum$judgment])
t2b.sum$judgment <- factor(t1b.sum$judgment, levels = c("Physical Impossibility","Improbability","Immorality","Violation Index"))
t2b.sum$`Violation Type` <- factor(c("Moral","Non-violation","Physical","Statistical")[t2b.sum$`Violation Type`])
t2b.sum$`Violation Type` <- factor(t1b.sum$`Violation Type`, levels=c("Physical","Statistical","Moral","Non-violation"))

fig2 <- ggplot(t2b.sum,aes(x=judgment, y=mean, fill=judgment))+
  ylab("Mean Rating across Scenarios") +
  xlab("") +
  ggtitle("Ratings of Each Violation Type") +
  facet_grid(~`Violation Type`) +
  #coord_cartesian(ylim=c(0,100)) +
  geom_bar(position="dodge",stat="identity") +
  geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.1, position=position_dodge(.9)) +
  guides(fill = guide_legend(title = "Judgment Type")) +
  theme_bw() +
  theme(
    plot.background = element_blank()
    ,panel.grid.major = element_blank()
    ,panel.grid.minor = element_blank()
    ,legend.text=element_text(size=rel(1.33))
    #,legend.position=c(.88,.88)
    ,legend.title=element_text(size=rel(1.45))
    ,strip.text = element_text(size=rel(1.5))
    ,axis.text.y=element_text(size=rel(1.5))
    ,axis.text.x=element_blank()
    ,axis.title.y=element_text(vjust=.9)
    ,axis.ticks = element_blank()
    ,axis.title=element_text(size=rel(1.65))
    ,plot.title = element_text(hjust = 0.5,size=rel(1.5))
  ) 

```


```{r fig.width=12, fig.height=8,echo=FALSE}

print(fig2)
```
